<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app{
            border: 1px solid #cccccc;
            padding: 10px;
        }
        .box{
            border: 1px solid #cccccc;
            margin-left: 50px;
            padding: 10px;
        }
        p{
            padding-left: 20px;
        }
        input{
            margin-left: 20px;
        }
    </style>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h3>父组件范围</h3>
        <p>msg:{{ msg }}</p>
        <input type="text" v-model="msg">
        <p>info:{{ info }}</p>
        <input type="text" v-model="info">
        <br><br>
        <child-one 
            :msg="msg" 
            @update-msg="updateMsg"
            :info="info"
            @update-info="updateInfo"
        ></child-one>
    </div>
</body>
<script type="text/x-template" id="one">
    <div class="box">
        <h3>子组件范围</h3>
        <p>msg:{{ msg }}</p>
        <input type="text" :value="msg" @input="setMsg($event.target.value)"> <br>
        <input type="text" v-model="msg"> <br>
        <input type="text" v-model="testMsg"> <br>
        <p>info:{{ info }}</p>
        <input type="text" v-model="testInfo">
    </div>
</script>
<script>
    Vue.component("ChildOne",{
        template:"#one",
        props:{
            msg:{
                type:String
            },
            info:String
        },
        computed:{
            testMsg:{
                get(){
                    return this.msg;
                },
                set(nv){
                    this.$emit( "update-msg",nv )
                }
            },
            testInfo:{
                get(){
                    return this.info;
                },
                set(nv){
                    this.$emit("update-info",nv)
                }
            }
        },
        methods: {
            setMsg(nv){
                this.$emit( "update-msg",nv )
            }
        },
    })
    new Vue({
        el:"#app",
        data:{
            msg:"父组件数据",
            info:"父组件的info"
        },
        methods: {
            updateMsg(nv){
                this.msg = nv;
            },
            updateInfo(nv){
                this.info = nv;
            }
        },
    })


</script>
</html>